package com.ustb.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.entity.QuestionCheckboxEntity;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ustb.springboot.dao.OptionDao;
import com.ustb.springboot.entity.OptionEntity;
import com.ustb.springboot.service.OptionService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@Service("optionService")
public class OptionServiceImpl extends ServiceImpl<OptionDao, OptionEntity> implements OptionService {

    @Resource
    private OptionDao optionDao;

    @Override
    public R delete(Map<String, Object> body) {
        QueryWrapper<OptionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
        return optionDao.delete(queryWrapper) == 1 ? R.ok(20000, "删除成功！") : R.error(2000, "删除失败！");
    }

    @Override
    public List<OptionEntity> queryWithId(Map<String, Object> body) {
        QueryWrapper<OptionEntity>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("question_id",body.get("question_id").toString());
        List<OptionEntity> optionEntityList = optionDao.selectList(queryWrapper);
        System.out.println(optionEntityList.size());
        return optionEntityList;
    }

    @Override
    public OptionEntity queryWithOptionId(String Option_id,String question_id) {
        System.out.println("Option_id"+Option_id);
        QueryWrapper<OptionEntity>queryWrapper =new QueryWrapper<>();
        queryWrapper.eq("order_id",Option_id).eq("question_id",question_id);
        List<OptionEntity> optionEntityList = optionDao.selectList(queryWrapper);
        if (optionEntityList.isEmpty() == false)
            return optionEntityList.get(0);
        else
            return null;
    }

}